<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var num =  parseInt(prompt('请输入一个数字'))

    function getVal(min, max) {
      return Math.floor(Math.random() * ( max - min + 1)) + min 
    }
    var flag = getVal(0, 10)

    while( num !== flag ) {
      if( num > flag ) {
        alert('猜大了')
        num =  parseInt(prompt('请输入一个数字'))
      } else if(num < flag) {
        alert('猜小了')
        num =  parseInt(prompt('请输入一个数字'))
      } 
    }
    
    alert('猜对了')
  </script>
</body>
</html>